package com.netafull.analyze;

import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class AnalyzeXMLForComments {
	public List<Comment> getRss(String path) throws IllegalArgumentException {
		List<Comment> data = new ArrayList<Comment>();
		URL url = null;
		try {

			url = new URL(path);
			URLConnection myurlcon = url.openConnection();
			myurlcon.setConnectTimeout(15000);
			myurlcon.setReadTimeout(15000);
			myurlcon.connect();

			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();
			XMLReader xr = sp.getXMLReader();
			AnalyzeXMLHandlerForComments myExampleHandler = new AnalyzeXMLHandlerForComments();
			xr.setContentHandler(myExampleHandler);
			xr.parse(new InputSource(url.openStream()));
			data = myExampleHandler.getParsedData();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return data;

	}
}
